import { Component } from '@angular/core';
import { NavController, NavParams, AlertController } from 'ionic-angular';
import { DataService } from '../../services/data';
import { AppGlobal } from '../../app/app.global';
/**
 * Generated class for the FeedbackPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@Component({
  selector: 'page-feedback',
  templateUrl: 'feedback.html',
  providers: [DataService]

})
export class FeedbackPage {

  content: string;
  constructor(public navCtrl: NavController, public navParams: NavParams, public dataService: DataService, public alertCtrl: AlertController) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad FeedbackPage');
  }

  submit() {
    let user_id = AppGlobal.getInstance().getUser().id;
    this.dataService.feedback(user_id, this.content).subscribe(data => {
      if (data.code === 0) {
        const alert = this.alertCtrl.create({
          title: '提示',
          subTitle: '提交成功！非常感谢您的建议 ~ ',
          buttons: [
            {
              text: 'ok',
              handler: () => {
                this.navCtrl.pop();
              }
            }
          ]
        });
        alert.present();
      }
    });
  }
}